<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('账单查询')" />
	<th:block th:include="include :: select2-css" />
	<th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">

    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="online-form">
					<div class="select-list">
						<ul>
							<li>
								年份：<select class="form-control" id="year" ></select>
							</li>
							<li>
								月份：<select class="form-control" id="month" ></select>
							</li>
							<li>
								使用单位：<select class="form-control" id="companyId" ></select>
							</li>
							<li>
								业务应用：<select class="form-control" id="businessNames" ></select>
							</li>
							<li>
								流量状态：<select class="form-control" id="stateName" ></select>
							</li>
							<li>
								流量区间：<input type="text" name="flow1"/>
										<span>-</span>
										<input type="text" name="flow2"/>
							</li>
							<li>
								资费区间：<input type="text" name="charge1"/>
										<span>-</span>
										<input type="text" name="charge2"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
	            <a class="btn btn-danger multiple disabled" onclick="javascript:batchForceLogout()" shiro:hasPermission="monitor:online:batchForceLogout">
	                <i class="fa fa-sign-out"></i> 强退
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-table-export-js" />
	<th:block th:include="include :: select2-js" />
	<th:block th:include="include :: bootstrap-select-js" />
	<script th:inline="javascript">
		var forceFlag = [[${@permission.hasPermi('monitor:online:forceLogout')}]];
		var prefix = ctx + "bill";

		$(function() {
		    var options = {
		    	uniqueId: "sessionId",
		        url: prefix + "/list",
		        exportUrl: prefix + "/export",
		        sortName: "lastAccessTime",
		        sortOrder: "desc",
				showFooter: false,
				showSearch: false,
				showRefresh: true,
				showToggle: false,
				showColumns: false,
				escape: false,
		        columns: [{
		            checkbox: true
		        },
		        {
                    title: "序号",
                    formatter: function (value, row, index) {
                 	    return $.table.serialNumber(index);
                    }
                },
		        {
		            field: 'cardNo',
		            title: 'SIM卡号',
					formatter:operateFormatter,
		        },
		        {
		            field: 'flowLimit',
		            title: '流量上限（M）',
		            sortable: true
		        },
		        {
		            field: 'flow',
		            title: '实际使用流量（M）'
		        },
		        {
		            field: 'charge',
		            title: '实际费用（元）'
		        },
		        {
		            field: 'stateName',
		            title: '状态'
		        },
		        {
		            field: 'ym',
		            title: '账单年月'
		        },
		        // {
		        //     field: 'status',
		        //     title: '会话状态',
		        //     align: 'center',
		        //     formatter: function(value, row, index) {
		        //         if (value == 'on_line') {
		        //             return '<span class="badge badge-primary">在线</span>';
		        //         } else if (value == 'off_line') {
		        //             return '<span class="badge badge-danger">离线</span>';
		        //         }
		        //     }
		        // },
		        {
		            field: 'companyName',
		            title: '使用单位',
		            sortable: true
		        },
		        {
		            field: 'businessNames',
		            title: '业务系统',
		            sortable: true
		        },
				{
					field: 'userName',
					title: '安装位置（使用人）',
					sortable: true
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var msg = '<a class="btn btn-danger btn-xs ' + forceFlag + '" href="javascript:void(0)" onclick="forceLogout(\'' + row.sessionId + '\')"><i class="fa fa-sign-out"></i>强退</a> ';
		                return msg;
		            }
		        }]
		    };
		    $.table.init(options);
		});

		function operateFormatter(value, row, index) {
			return ['<a onclick=cardDetail('+ value + ') >'+value+'</a>'
			].join('')
		}
		function cardDetail(value) {
			window.SIM = value;
			$.modal.openTab('SIM卡信息',ctx+"base_card/cardDetail?cardNo="+value);
		}

		$(document).ready(function(){
			req("post","/data_info/getYear","year")
			$('#year').on('change', function (e) {
				req("post","/data_info/getMonth","month")
			});
			$('#month').on('change', function (e) {
				req("post","/data_info/search","companyId")
			});
			$('#companyId').on('change', function (e) {
				req("post","/data_info/getYear","year")
			});
			$('#year').select2({
				data:[{id:"66666666", text:"66666666"}]
			})
		});

		function req(type,url,id){
			$.ajax({
				type:type,
				url: url,
				dataType:"json",
				function(data){
					$('#'+id).select2({
						data:data
					})
				},
				error:function(jqXHR){
					console.log("Error: "+jqXHR.status);
				}
			});
		}

		// 单条强退
		function forceLogout(sessionId) {
		    $.modal.confirm("确定要强制选中用户下线吗？", function() {
		    	var data = { "ids": sessionId };
		        $.operate.post(prefix + "/batchForceLogout", data);
		    })
		}

		// 批量强退
		function batchForceLogout() {
		    var rows = $.table.selectColumns("sessionId");
		    if (rows.length == 0) {
		        $.modal.alertWarning("请选择要强退的用户");
		        return;
		    }
		    $.modal.confirm("确认要强退选中的" + rows.length + "条数据吗?", function() {
		        var url = prefix + "/batchForceLogout";
		        var data = { "ids": rows.join() };
		        $.operate.post(url, data);
		    });
		}
	</script>

</body>
</html>